nums = [2, 3, 1, 1, 4]
nums = [2, 0]
nums = [2, 5, 0, 0]

nums = [0, 1]
nums = [2, 0, 0]

nums = [3, 2, 1, 0, 4]
// var canJump = function (nums) {
//     let len = nums.length
//     for (let i = 0; i < len;) {
//         if (i < len && nums[i + nums[i]] === 0 && i + nums[i] < len) {
//             console.log(1);
//             i++
//             continue
//         }
//         i += nums[i]
//         if (i === len - 1) return true
//         if (nums[i] === 0) return false
//     }
//     return true
// };
var canJump = function (nums) {
    let len = nums.length
    let maxDistance = 0
    for (let i = 0; i < len; i++) {
        if (i <= maxDistance) {
            maxDistance = Math.max(maxDistance, i + nums[i])
            console.log(maxDistance);
            if (maxDistance >= len - 1) {
                return true
            }
        }
    }
    return false
};

console.log(canJump(nums));
